#include "pvmandroidtestex.h"
#include "pvm/pvmhelperapi.h"
#include <android/log.h>

void PVMCALL MyFreeMemmoryProc(void* memblock)
{
	delete[] ((char*)memblock);
}

PVMAUDIO loadAudioFromBuffer(void* data, int len)
{
	if(data==NULL)
		return (PVMAUDIO)1;
	if(len<=0)
		return (PVMAUDIO)2;
	PVMAUDIO audio = 0;
	char* dataCopy = new char[len];
	if(dataCopy==NULL)
		return (PVMAUDIO)3;
	memcpy(dataCopy, data, len);
	IPvmInStream* inStream = PVMHCreateMemoryInputStream((pvm_int8*)dataCopy, len, true, MyFreeMemmoryProc);
	if(inStream==NULL)
		return (PVMAUDIO)4;
	__android_log_write(ANDROID_LOG_DEBUG, "pvmandroidtest.c", "PVMHCreateMemoryInputStream\n");
	pvm_bool sourceOwned = false;
	audio = PVMAudioOpenStream(inStream, 0/*EPVM_LOADTOMEMORY*/, &sourceOwned);
	__android_log_write(ANDROID_LOG_DEBUG, "pvmandroidtest.c", "PVMAudioOpenStream\n");
	if(!sourceOwned)
		delete inStream;
	return audio;
}
